package net.zjitc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.zjitc.entity.Mycollect;
import net.zjitc.entity.Recruit;
import net.zjitc.entity.VO.RecruitVo;
import net.zjitc.mapper.MycollectMapper;
import net.zjitc.mapper.RecruitMapper;
import net.zjitc.service.IMycollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @auther 郭梦婷
 * @create 2022-05-30 21:33:24
 * @describe 服务实现类
 */
@Service
@Transactional
public class MycollectServiceImpl extends ServiceImpl<MycollectMapper, Mycollect> implements IMycollectService {

    @Autowired
    private MycollectMapper mycollectMapper;
    @Autowired
    private RecruitMapper recruitMapper;

    @Override
    public Mycollect IfCollect(Integer recruitid, String username) {
        QueryWrapper<Mycollect> wrapper=new QueryWrapper<>();
        wrapper.eq("recruitid",recruitid).eq("username",username);
        Mycollect mycollect = mycollectMapper.selectOne(wrapper);
        return mycollect;
    }

    @Override
    public int DeleteCollect(Integer recruitid, String username) {
        QueryWrapper<Mycollect> wrapper=new QueryWrapper<>();
        wrapper.eq("recruitid",recruitid).eq("username",username);
        int delete = mycollectMapper.delete(wrapper);
        return delete;
    }

    @Override
    public Page<RecruitVo> getMyCollectByUsername(String username, Integer pagenum, Integer pagesize) {
        Page<RecruitVo> page=new Page<>(pagenum,pagesize);
        page= recruitMapper.getMyCollectByUsername(page,username);

        return page;
    }
}
